package cn.micai.base.thread;

import java.util.Iterator;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;

/**
 * 描述：并发类容器
 * <p>
 *
 * @author: 赵新国
 * @date: 2018/2/22 16:10
 */
public class UserCopyOnWrite {

    public static void main(String [] args){
        // ArrayList怎样使用，CopyOnWriteArrayList就怎样使用
        CopyOnWriteArrayList<String> cwal = new CopyOnWriteArrayList<>();
        cwal.add("a");
        cwal.add("b");
        for (String str : cwal) {
            System.out.println("str: " + str);
        }
        // Set怎样使用，CopyOnWriteArraySet就怎样使用
        CopyOnWriteArraySet<String> cwas = new CopyOnWriteArraySet<>();
        cwas.add("c");
        cwas.add("d");
        for (Iterator iterator = cwas.iterator(); iterator.hasNext();) {
            String string = (String) iterator.next();
            System.out.println("string: " + string);
        }
    }
}
